package com.llh.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * sqlsession工具类
 */
public class SqlSessionUtil {
    public static SqlSessionFactory sqlSessionFactory;
    static {
        //初始化 SqlSessionFactory
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        sqlSessionFactory = sqlSessionFactoryBuilder.build(SqlSessionUtil.class.getClassLoader().getResourceAsStream("mybatis-config.xml"));
    }
    //获取sqlSession
    public static SqlSession getSqlSesion(){
        //设置为自动提交
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        return sqlSession;
    }
}
